//配置地址选择插件目录
layui.config({
    base: './js/layui/mods/'
    , version: '1.0'
});
layui.use(['layer', 'laydate','upload', 'form', 'layarea'], function () {
    var laydate = layui.laydate,
     form = layui.form, 
     upload = layui.upload, 
     layarea = layui.layarea;
    //调用生日弹出层
    laydate.render({
        elem: '#birthday',
    });
    //城市的三级联动
    layarea.render({
        elem: '#area-picker',
        change: function (res) {
            //选择结果
            console.log(res);
        }
    });
      //  头像上传
    var uploadInst = upload.render({
        elem: '#user_editimg',
        url: 'https://httpbin.org/post', //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
        before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#user_img').attr('src', result); //图片链接（base64）
            });
            layer.msg('上传中', {icon: 16, time: 0});
        },
        done: function(res){
        layer.msg('上传成功');
        $("#user_editimg").hide()
        $(".user_edit .layui-upload .motai .tip").show()
        if(res.code == 1){
            return layer.msg('上传成功');
        }
        },
        error: function(){
            layer.msg('上传失败');
        },
    });  
      //监听提交用户编辑内容
    form.on('submit(submituser_edit)', function(data){
        layer.msg(JSON.stringify(data.field));
        return false;
    });  
});


// 获取邮箱验证码
function get_verification(obj) {
    var email_ =$(obj).parents('.layui-input-block').find(".layui-input[name='address_email']").val();
    if(!/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(email_)){
       layer.msg('请输入正确的邮箱地址');
       return false;
    }
    if ($(obj).hasClass("time_bg")) {
        return false;
    }
    $(obj).addClass('time_bg');
    var time = 60;
    var time60 = setInterval(function () {
        time = time - 1
        if (time == 0) {
            time = 0
        }
        $(obj).html('再次发送(' + time + 'S)')
        if (time == 0) {
            clearInterval(time60)
            $(obj).removeClass('time_bg');
            $(obj).text('验证');
        }
    }, 1000);
}
// 修改手机号
function modifyiphone(obj){
  var iphone= $(obj).parents(".text_").find(".layui-input[name='address_iphone']");
  var number= $(obj).parents(".text_").find(".number");
  iphone.show();
  iphone.focus();
  number.hide()
  $(obj).hide()
}